package com.cj.service;

import com.cj.dao.CourseDetailDao;
import com.cj.entity.Coursedetail;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CourseDetailService {
    CourseDetailDao dao = new CourseDetailDao();
    public int insertCourseDetail(Coursedetail c) {
        String sql="insert into coursedetail values(null,?,?,?,?,?)";
        return dao.update(sql, c.getName(), c.getType(), c.getUrl(), c.getStart_data(), c.getCid());

    }

    public Map<String, List<Coursedetail>> findCourseDetail(String cid) {
//        group by 分组
        String sql ="select * from coursedetail where cid =? group by type";
        HashMap<String, List<Coursedetail>> map = new HashMap<>();
        List<Coursedetail> coursedetailList = dao.getEntities(sql, Coursedetail.class, cid);

        for (Coursedetail coursedetail : coursedetailList) {
            List<Coursedetail> coursedetailList1 = dao.getEntities("select * from coursedetail where cid=? and type=?", Coursedetail.class, cid, coursedetail.getType());
            map.put(coursedetail.getType(),coursedetailList1);
        }

        return map;
    }
}
